{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2025 Teclib' and contributors.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{# @var form                   Glpi\Form #}
{# @var comment                Glpi\Form\Comment|null #}
{# @var section                Glpi\Form\Section|null #}
{# @var can_update             bool #}

{% import 'components/form/fields_macros.html.twig' as fields %}

{% set base_field_options = {
    'is_horizontal': false,
    'full_width'   : true,
    'no_label'     : true,
} %}
{% set comment = comment|default(null) %}

<section
    role="option"
    class="d-flex"
    data-glpi-form-editor-block
    data-glpi-form-editor-comment
    data-glpi-form-editor-condition-type="{{ enum('Glpi\\Form\\Condition\\Type').COMMENT.value }}"
    data-glpi-draggable-item
>
    <section
        data-glpi-form-editor-on-click="set-active"
        data-glpi-form-editor-comment-details
        class="card flex-grow-1"
        aria-label="{{ __("Comment details") }}"
    >
        <div
            class="card-status-start bg-primary"
            data-glpi-form-editor-active-comment-status-indicator
        ></div>
        <div class="card-body">
            <div class="d-flex">
                <i
                    class="glpi-form-editor-question-handle ti ti-grip-horizontal cursor-grab ms-auto me-auto mt-n3 mb-n2"
                    data-glpi-form-editor-question-handle
                    draggable="true"
                ></i>
            </div>
            {# Display comment's title #}
            <div class="d-flex mt-n1 mb-3 align-items-center">
                <input
                    class="form-control content-editable-h2 mb-0"
                    type="text"
                    name="name"
                    value="{{ comment is not null ? comment.fields.name : '' }}"
                    placeholder="{{ __("Add a title...") }}"
                    aria-label="{{ __("Comment title") }}"
                    data-glpi-form-editor-dynamic-input
                    data-glpi-form-editor-on-input="compute-dynamic-input"
                    data-glpi-form-editor-comment-details-name
                />
                <span data-glpi-form-editor-required-mark class="text-danger d-none">*</span>

                <div class="ms-auto"></div>

                {# Visibility dropdown #}
                {{ include('pages/admin/form/conditional_visibility_dropdown.html.twig', {
                    'item': comment,
                    'type': "Glpi\\Form\\Comment",
                }, with_context = false) }}

                {# Duplicate comment #}
                <i
                    class="ti ti-copy ms-3 cursor-pointer"
                    data-bs-toggle="tooltip"
                    data-bs-placement="top"
                    title="{{ __("Duplicate comment") }}"
                    data-glpi-form-editor-on-click="duplicate-comment"
                    data-glpi-form-editor-comment-extra-details
                ></i>

                {# Delete comment #}
                <i
                    role="button"
                    class="ti ti-trash ms-3 cursor-pointer"
                    data-bs-toggle="tooltip"
                    data-bs-placement="top"
                    title="{{ __("Delete") }}"
                    aria-label="{{ __("Delete") }}"
                    data-glpi-form-editor-on-click="delete-comment"
                    data-glpi-form-editor-comment-extra-details
                ></i>

                {# Extra actions #}
                <div class="dropdown ms-3 cursor-pointer d-flex align-items-center">
                    <i
                        class="ti ti-dots-vertical show"
                        data-bs-toggle="dropdown"
                        aria-expanded="false"
                        role="button"
                        title="{{ __('More actions') }}"
                    ></i>
                    <ul class="dropdown-menu" data-bs-popper="none">
                        <li>
                            <button
                                type="button"
                                class="dropdown-item"
                                data-glpi-form-editor-on-click="show-visibility-dropdown"
                            >
                                <i class="ti ti-eye-cog me-2"></i>
                                <span>{{ __("Configure visibility") }}</span>
                            </button>
                        </li>
                    </ul>
                </div>
            </div>

            {# Display common fields #}
            <div
                class="content-editable-tinymce"
                data-glpi-form-editor-comment-description
                {# Mark as secondary if empty #}
                {{ comment is null or comment.fields.description|length == 0 ? "data-glpi-form-editor-active-comment-extra-details" : "" }}
            >
                {% set load_editor = comment is not null and comment.fields.description|length > 0 %}
                {{ fields.textareaField(
                    'description',
                    comment is not null ? comment.fields.description : '',
                    __('Description'),
                    base_field_options|merge({
                        'placeholder': __('Add a description'),
                        'aria_label': __("Comment description"),
                        'enable_richtext': true,
                        'add_body_classes': ['content-editable-tinymce-editor', 'text-muted'],
                        'editor_height': "0",
                        'rows' : 1,
                        'toolbar_location': 'bottom',
                        'init': load_editor,
                        'mb': 'mb-0',
                        'additional_attributes': {
                            'data-glpi-loaded': load_editor ? "true" : "false"
                        }
                    })
                ) }}
            </div>
        </div>

        {# Common hidden data #}
        <input
            type="hidden"
            name="uuid"
            value="{{ comment is not null ? comment.fields.uuid : '' }}"
        />
        <input
            type="hidden"
            name="forms_sections_uuid"
            value="{{ section is not null ? section.fields.uuid : '' }}"
        />
        <input
            type="hidden"
            name="vertical_rank"
            value="{{ comment is not null ? comment.fields.vertical_rank : 0 }}"
        />
        <input
            type="hidden"
            name="horizontal_rank"
            value="{{ comment is not null ? comment.fields.horizontal_rank : 0 }}"
        />
    </section>

    <div data-glpi-form-editor-comment-extra-details>
        {{ include('pages/admin/form/form_toolbar.html.twig', {
            'can_update'     : can_update,
            'form'           : form,
            'vertical_layout': true
        }, with_context = false) }}
    </div>
    <div data-glpi-form-editor-question-drag-merge></div>
</section>
